#define InfraredPin A0//红外线传感器

int data = 0;

void setup() {
Serial.begin(9600);
pinMode(InfraredPin,INPUT);
}

void loop() {


if(Serial.available()>0){
  data = Serial.read();
  if(data == 'H'){
//    Serial.println("Good Job!");
    
uint16_t value = 0;
for(int i=0;i<20;i++){//平均滤波
  value=value + analogRead(InfraredPin);
  delay(5);
}

//uint16_t range = get_gp2d12(value/5);
Serial.println(value/20);
//Serial.print(range);
//Serial.println("mm");
//Serial.println();
delay(500);

  }
}


}

//
////analog-read value to distance value
//uint16_t get_gp2d12(uint16_t value){
//  return ((67870.0/(value-30))-40.0);
//}
